(function () {
    var init, select, server, user, password, dbName, get, makeHidden, bind,
            switcher;
    
    init = function () {
        select = get('driver');
        server = get('dbServerRow');
        user = get('dbUserRow');
        password = get('dbPasswordRow');
        dbName = get('dbName');
        bind(select, 'change', switcher);
        switcher();
    };
    
    switcher = function () {
        var poSql;
        poSql = select.value == 'PoSQL';
        makeHidden(server, poSql);
        makeHidden(user, poSql);
        makeHidden(password, poSql);
        dbName.value = poSql ? 'database' : '';
    };
    
    bind = function (element, event, listener) {
        var oldListener;
        if (element.addEventListener) {
            element.addEventListener(event, listener, false);
        } else if (element.attachEvent) {
            element.attachEvent('on' + event, listener);
        } else {
            oldListener = element['on' + event];
            element['on' + event] = function () {
                if (oldListener instanceof Function) {
                    oldListener();
                }
                listener();
            }
        }
    };
    
    makeHidden = function (element, hidden) {
        element.style.display = hidden ? 'none' : '';
    };
    
    get = function (id) {
        return document.getElementById(id);
    };
    
    if (window.addEventListener) {
        addEventListener('DOMContentLoaded', init, false);
    } else if (window.attachEvent) {
        attachEvent('onload', init);
    } else {
        (function () {
            var onload;
            onload = window.onload;
            window.onload = function (e) {
                if (onload instanceof Function) {
                    onload(e);
                }
                init();
            };
        }());
    }
}());
